<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:email="http://saxonextensions.org/email">
  <!-- Home directory for eml output, passed from command line -->
  <xsl:param name="home"/>
  <!-- Default output format -->
  <xsl:output method="xhtml" encoding="ISO-8859-1" indent="yes" />
	<!-- Configure Email Emitter output -->
  <xsl:output name="email"
              xmlns:email="http://saxonextensions.org/email"
              method="email:org.saxonextensions.eml.emitter.EMLEmitter"
              indent="yes"
              encoding="ISO-8859-1" />
  <!-- Root template -->
  <xsl:template match="/">
    <!-- For each row -->
    <xsl:for-each select="rows/row">
      <!-- construct a unique eml file name -->
      <xsl:variable name="output-name" select="concat('file:///',$home,'/eml/',first_name,'.',last_name,'.',position(),'.eml')"/>      
      <!-- This tells xslt processor to use configured earlier email emitter -->
      <xsl:result-document format="email" href="{$output-name}">
        <!-- set eMail Subject -->
        <email:Subject>Test</email:Subject>
        <!-- Set From address -->
        <email:From name="tester">test-source@test.com</email:From>
        <!-- Set To addresses -->
        <email:To name="{concat(first_name,' ',last_name)}"><xsl:value-of select="email" /></email:To>
        <!-- Create an XHTML body part -->
        <email:Part Content-Type="text/html">
          <html><body><h1>Hello World!</h1></body></html>
        </email:Part>
      </xsl:result-document>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>